package com.spring.boot.pojo;
//import lombok.Data;

import java.util.HashMap;

/**
 * 统一返回结果
 */
//@Data
public class JsonResult {
    private int code;       //返回码 非0即失败
    private String msg;     //消息提示
    private Object data; //返回的数据

    public JsonResult(){};

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public JsonResult(int code, String msg , Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static Object success() {
        return success(new HashMap<>(0));
    }
    public static JsonResult success(Object data) {
        return new JsonResult(0, "成功",data);

    }

    public static Object failed() {
        return failed("失败");
    }
    public static Object failed(String msg) {
        return failed(1000, msg);
    }
    public static Object failed(int code, String msg) {
        return new JsonResult(code, msg,new HashMap<>(0));
    }

    public static Object exception() {
        return new JsonResult();
    }
    public static Object exception(Object data) {
        return new JsonResult(201, "提示", data);

    }

}
